﻿using CodeSystem.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web;
using System.Web.Http.Filters;

namespace CodeSystem.App_Start
{
    public class ApiAttributeEx: ExceptionFilterAttribute
    {
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            //记录异常日志

            //响应请求返回数据
            var result = new ApiResultMd
            {
                code = ResponseCode.Exception,
                data = null,
                msg = actionExecutedContext.Exception.Message
            };
            actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(result);
            base.OnException(actionExecutedContext);
        }
    }
}